package com.echo.fm.platform.database;

import com.echo.util.ErrorException;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Order;

import java.io.Serializable;
import java.util.List;

public interface IHibernatePersistence {
   /**
	 * 打开连接
	 * @return
	 * @throws ErrorException
	 */
	Session openSession() throws ErrorException;
	/**
	 * 默认分页数据信息
	 * @param clazz
	 * @param criterions
	 * @param order
	 * @param firstResult
	 * @return
	 * @throws ErrorException
	 */
	public List<? extends Object> pagesList(Class<?> clazz, List<Criterion> criterions, Order order, int firstResult) throws ErrorException;
	
	public List<? extends Object> pagesList(Class<?> clazz, List<Criterion> criterions, List<Order> orders, int firstResult) throws ErrorException;
	
	public List<? extends Object> pagesList(Class<?> clazz, List<Criterion> criterions, Order order, int firstResult, int maxResults) throws ErrorException;
	
	public int pagesCount(Class<?> clazz, List<Criterion> criterions) throws ErrorException;
	/**
	 * 查询对象列表信息
	 * @param clazz 对象类型
	 * @param criterions 查询条件
	 * @return
	 * @throws ErrorException
	 */
	public List<? extends Object> searchList(Class<?> clazz, List<Criterion> criterions) throws ErrorException;
	/**
	 * 查询对象列表信息
	 * @param clazz 对象类型
	 * @param criterions 查询条件
	 * @param order 排序信息
	 * @return
	 * @throws ErrorException
	 */
	public List<? extends Object> searchList(Class<?> clazz, List<Criterion> criterions, Order order) throws ErrorException;
	/**
	 * 查询对象列表信息
	 * @param clazz 对象类型
	 * @param criterions 查询条件
	 * @param order 排序信息
	 * @param firstResult 起始记录 默认 0
	 * @param maxResults 记录数量
	 * @return
	 * @throws ErrorException
	 */
	public List<? extends Object> searchList(Class<?> clazz, List<Criterion> criterions, Order order, Integer maxResults) throws ErrorException;
	/**
	 * 查询对象列表信息
	 * @param clazz 对象类型
	 * @param criterions 查询条件
	 * @param order 排序信息
	 * @param firstResult 起始记录
	 * @param maxResults 记录数量
	 * @return
	 * @throws ErrorException
	 */
	public List<? extends Object> searchList(Class<?> clazz, List<Criterion> criterions, Order order, Integer firstResult, Integer maxResults) throws ErrorException;
	
	public Object searchByUniqueCriterion(Class<?> clazz, List<Criterion> criterions) throws ErrorException;
	
	public Object searchByUniqueCriterion(Class<?> clazz, Criterion criterion) throws ErrorException;
	
	public List<? extends Object> searchByCriterion(Class<?> clazz, Criterion criterion, Order order) throws ErrorException;
	
	public Object searchById(Class<?> clazz, Criterion criterion) throws ErrorException;
	/**
	 * 添加对象
	 * @return
	 * @throws ErrorException
	 */
	public Serializable create(Object object) throws ErrorException;
	
	/**
	 * 更新对象
	 * @return
	 * @throws ErrorException
	 */
	public void update(Object object) throws ErrorException;
	/**
	 * 删除对象
	 * @return
	 * @throws ErrorException
	 */
	public void delete(Object object) throws ErrorException;
	/**
	 * 关闭连接
	 * @return
	 * @throws ErrorException
	 */
	public void closeSession(Session session) throws ErrorException;
	/**
	 * 初始化 criterions
	 * @param criterions 
	 */
	public List<Criterion> initCriterion(List<Criterion> criterions);
	/**
	 * 加载 criterions
	 * @param criterions
	 */
	public void loadCreterions(Criteria criteria, List<Criterion> criterions);
	
	public String searchCurrSeq(String seqname) throws ErrorException;
		
	public void deletewithSQL(String sql) throws ErrorException;

	void save(Object object) throws ErrorException;
}
